package com.anolesoft.yr.mbus.cont.service.impl;

import com.anolesoft.yr.mbus.cont.dao.ContContentDao;
import com.anolesoft.yr.mbus.cont.dao.ContMainDao;
import com.anolesoft.yr.mbus.cont.entity.ContContent;
import com.anolesoft.yr.mbus.cont.entity.ContMain;
import com.google.common.collect.Lists;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;

public class CreatWordServiceImpl {
    @Autowired
    private ContMainDao contMainDao;
    @Autowired
    private ContContentDao contContentDao;

    public void CreateWord(String contMainUid){
        ContMain contMain = contMainDao.selectById(contMainUid);
        List<ContContent> contContents = contMain.getContContents();

        List<ContContent> list = Lists.newArrayList();
        exeucte(contContents, list);
        for (int i = 0; i < list.size(); i++) {

        }


    }

    public void exeucte(List<ContContent> children, List<ContContent> save) {
        for (ContContent contContent : children) {
            save.add(contContent);
            List<ContContent> contContentsContent = contContent.getContContentsContent();
            save.addAll(contContentsContent.stream().sorted(Comparator.comparing(ContContent::getOrder)).collect(Collectors.toList()));
            List<ContContent> contContentsTitle = contContent.getContContentsTitle();
            if (!contContentsTitle.isEmpty()) {
                exeucte(contContentsTitle, save);
            }
        }
    }


}
